<include file="public@header"/>
<style>
    #add{
        margin-left: 30px;font-size: 20px;font-weight: 700
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Wuye/payList')}">缴费记录</a></li>
        <li class="active"><a href="{:url('Wuye/payAdd')}">添加缴费记录</a></li>
        <li><a href="{:url('Wuye/payCateAdd')}">添加缴费类型</a></li>
    </ul>
    <notempty name="cate">
    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('Wuye/paySvae')}">

        <div id="addDiv">
            <div>
                <div class="form-group">
                    <span class="form-required">优先显示用户备注</span>

                    <label class="col-sm-2 control-label"><span class="form-required">*</span>缴费人:</label>
                    <div class="col-md-6 col-sm-10">
                        <select class="form-control" name="openid">
                            <notempty name="list">
                                {:widget('Wechat/payFans', ['openid'=>$list['openid']])}
                            <else/>
                                {:widget('Wechat/payFans')}
                            </notempty>

                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label"><span class="form-required">*</span>总计:</label>
                    <div class="col-md-6 col-sm-10">
                        <input type="text" class="form-control" value="{$list.total|default='0'}" id="total">
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-sm-2 control-label"><span class="form-required">*</span>缴费详细:</label>
                    <table class="col-md-6 col-sm-10 table table-hover table-bordered table-list"style="width: 50% !important;">
                        <thead>
                        <tr>
                            <th width="30%">缴费类型</th>
                            <th width="20%">金额</th>
                            <th width="30%">起始时间</th>
                            <th width="20%">截止时间</th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>

                        <notempty name="resList">
                            <volist name="resList" id="voResList">
                                <tr>
                                    <td>
                                        <select class="form-control" name="cate_id[]">
                                            {:widget('Wechat/payCate', ['id'=>$voResList['cate_id']])}
                                        </select>
                                    </td>
                                    <td>
                                        <input type="text" class="form-control num" name="num[]" value="{$voResList.num}">
                                        <span class="spanId" style="display: none">{$voResList.id}</span>
                                    </td>
                                    <td>
                                        <input class="js-date" type="text" name="start_time[]" value="{$voResList.start_time}">
                                    </td>
                                    <td>
                                        <input class="js-date" type="text" name="end_time[]" value="{$voResList.end_time}">
                                    </td>
                                    <input type="hidden" name="total[]" class="total" value="{$voResList.total}">
                                    <input type="hidden" name="id[]" value="{$voResList.id}">
                                </tr>
                            </volist>
                            <else />
                            <tr>
                                <td>
                                    <select class="form-control" name="cate_id<empty name="list">[]</empty>" >
                                    <notempty name="list">
                                        {:widget('Wechat/payCate', ['id'=>$list['cate_id']])}
                                        <else/>
                                        {:widget('Wechat/payCate')}
                                    </notempty>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" class="form-control num" name="num<empty name="list">[]</empty>" value="{$list.num|default=''}">
                                </td>
                                <td>
                                    <input class="js-date" type="text" name="start_time<empty name="list">[]</empty>" value="{$list.start_time|default=''}">
                                </td>
                                <td>
                                    <input class="js-date" type="text" name="end_time<empty name="list">[]</empty>" value="{$list.end_time|default=''}">
                                </td>

                                <td>
                                    <a href="javascript:;" id="add" onclick="add(this);">[+]</a>
                                </td>
                            </tr>
                            <input type="hidden" name="total" class="total" value="">
                        </notempty>
                        </tbody>
                    </table>
                </div>

            </div>
        </div>
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary js-ajax-submit">{:lang("SAVE")}</button>
            </div>
        </form>
    <else />
        <h1>先添加缴费类型</h1>
    </notempty>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">

    $(".num").change(function(){
        var total = 0;
        $(".num").each(function(){
            total = total +parseInt($(this).val());
        });
        $('#total').val(total);
        $('.total').val(total);
    });
    function add(obj) {
        var addDiv = $(obj).parent().parent().parent();
        var html = '<tr>\n' +
            '                                <td>\n' +
            '                                    <select class="form-control" name="cate_id<empty name="list">[]</empty>">\n' +
            '                                    <notempty name="list">\n' +
            '                                        {:widget(\'Wechat/payCate\', [\'id\'=>$list[\'cate_id\']])}\n' +
            '                                        <else/>\n' +
            '                                        {:widget(\'Wechat/payCate\')}\n' +
            '                                    </notempty>\n' +
            '                                    </select>\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input type="text" class="form-control num" name="num<empty name="list">[]</empty>" value="{$list.num|default=\'\'}">\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input class="js-date" type="text" name="start_time<empty name="list">[]</empty>"  value="{$list.start_time|default=\'\'}">\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input class="js-date" type="text" name="end_time<empty name="list">[]</empty>" value="{$list.end_time|default=\'\'}">\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <a href="javascript:;" id="add" onclick="reduce(this);">[-]</a>\n' +
            '                                </td>\n' +
            '                            </tr>';
        addDiv.append(html);
        var dateInput = $("input.js-date");
        if (dateInput.length) {
            Wind.use('datePicker', function () {
                dateInput.datePicker();
            });
        }
        $(".num").change(function(){
            var total = 0;
            $(".num").each(function(){
                total = total +parseInt($(this).val());
            });
            $('#total').val(total);
            $('.total').val(total);
        });
    }
    function reduce(obj) {
        var addErDiv = $(obj).parent().parent();
        var addDiv = $(obj).parent().parent();
        var thisVal = $(obj).parent().siblings().children('.num').val();
        console.log($(obj).parent().siblings().children('.num').val());
        var total = $('#total').val();
        $('#total').val(total -thisVal);
        addErDiv.remove();
    }



</script>
</body>
</html>